/******************************************************************************
 * 
 *  @desc: iview表单的校验规则
 *  @variation TRIGGER 统一校验事件（iview提供的事件有blur、change等）
 * 
 * ***************************************************************************/

const TRIGGER = 'change';

export default function (r,field) {
    const BASERULES = {
        // 必填
        required: {
            required: true,
            type: (()=>{
                let type = 'string';
                switch (field.type) {
                    case 'select3':
                    case 'select4':
                    case 'checkbox':
                        type = 'array'
                        break;

                    default:
                        break;
                }
                
                return type;
            })(),
            message: "该字段为必填项",
            trigger: TRIGGER
        },
        // 身份证
        idcard: {
            type: "string",
            max: 18,
            min: 18,
            pattern: /^\d{6}(1[8-9]|[2-9][0-9])\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X|x)$/,
            message: "请输入正确的身份证号",
            trigger: TRIGGER
        },
        // 手机号码
        phone: {
            pattern: /^1[3456789]\d{9}$/, 
            message: "手机号码格式不正确", 
            trigger: TRIGGER
        }
    };
    return BASERULES[r];
};

